#!/usr/bin/python
# pylint: disable-msg = E1101, C0301
'''
Created by Colin Gillespie <c.gillespie@ncl.ac.uk>
Last Changed on: $LastChangedDate$
Rev: $Rev$

Use to get the RHS of the moment-equation.
If the all rate laws are polynomial, then this is just the derivative of the moment wrt to time.
If the rate law is rational, then it can be more complicated.

'''
from __future__ import division
__revision__ = '$Rev$'

#Import non-standard modules
from mrange import mrange
from Factorial import binomial
from VariableDict import Variables, TimeVariables
from sympy import expand, sympify, diff



def getTimeDerivative(mom_equ, gdd):
    t = sympify('t')
    entry = 0
    print gdd.h.items()
    for coeffs, values in gdd.h.items():
        i_n_value = tuple([n+i for n, i in zip(mom_equ, coeffs)])
        moment = TimeVariables().getMoment(i_n_value)
        entry += values*diff(moment, t)

    return sympify(entry).expand()                      

    
    



if __name__ == '__main__':
    Variables().initialise()
    TimeVariables().initialise()
    import GetReactionInformation
    #gdd = GetReactionInformation.GetStoichiometryDict(sbml_file = 'xml_files/test/imdeath.xml')
    gdd = GetReactionInformation.GetStoichiometryDict(sbml_file = 'xml_files/test/rational_bi.xml')    
    
    x =  getTimeDerivative((1,0), gdd)
    print x
#    y= Variables().getMoment((1,))
#    yt = diff(y,sympify('t'))
#    print x.coeff(yt)
#    print (x - yt*x.coeff(yt)).expand()
#    print dir(x)
    
